package vn.demand.dragon.controller
{
	import com.salesbuilder.control.TabManager;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	import vn.demand.dragon.model.QuotationProxy;
	import vn.demand.dragon.view.QuotationFormMediator;
	import vn.demand.dragon.view.QuotationLineFormMediator;
	import vn.demand.dragon.view.QuotationPanelMediator;
	import vn.demand.dragon.view.components.QuotationPanel;
	
	public class OpenQuotationCommand extends SimpleCommand
	{
		override public function execute( note:INotification ) :void    
		{
			var quotationVO:Object = note.getBody();
			if (facade.hasMediator(QuotationPanelMediator.makeId(quotationVO))) {
				TabManager.openTab(QuotationPanel, QuotationPanelMediator.makeId(quotationVO));
				return;
			}
			var ui:QuotationPanel = TabManager.openTab(QuotationPanel, QuotationPanelMediator.makeId(quotationVO)) as QuotationPanel;
            facade.registerMediator(new QuotationPanelMediator(quotationVO, QuotationPanelMediator.makeId(quotationVO), ui));
            
            var formId:String = QuotationFormMediator.makeId(quotationVO);
            facade.registerProxy(new QuotationProxy(formId, quotationVO));
            facade.registerMediator(new QuotationFormMediator(quotationVO, formId, ui.quotationForm));
            
            var lineMediatorId:String = QuotationLineFormMediator.makeId(quotationVO);
            facade.registerProxy(new QuotationProxy(lineMediatorId, quotationVO));
            facade.registerMediator(new QuotationLineFormMediator(quotationVO, lineMediatorId, ui.quotationLineForm));
        }

	}
}